home *** CD-ROM | disk | FTP | other *** search
/ Treccani Italiana Di Scienze Lettere Ed Arti / [Enciclopedia] Treccani Italiana di scienze lettere ed arti.iso / pc / data / xxi_appendice_dvd.swf / scripts / __Packages / CAppendiceLemmaViewerSearchResult.as < prev    next >
Text File  |  2007-11-08  |  6KB  |  164 lines

  1. class CAppendiceLemmaViewerSearchResult extends mx.core.UIObject
  2. {
  3.    function CAppendiceLemmaViewerSearchResult()
  4.    {
  5.       super();
  6.       this.mInitialized = false;
  7.       this.inputboxLwSearchResults.text = "";
  8.       this.doLater(this,"init");
  9.    }
  10.    function init()
  11.    {
  12.       this.mInitialized = true;
  13.       if(!_global.gHtmlRenderer)
  14.       {
  15.          _global.gHtmlRenderer = _root.createTextField("txt_globalhtmlRenderer",1,0,0,100,200);
  16.          _global.gHtmlRenderer.html = true;
  17.          _global.gHtmlRenderer._visible = false;
  18.       }
  19.       this.mHtmlRenderer = _global.globalhtmlRenderer;
  20.       this.inputboxLwSearchResults.html = true;
  21.       this.inputboxLwSearchResults.embedFonts = _global.gUseEmbeddedFont;
  22.       this.inputboxLwSearchResults.styleSheet = _global.gStyleManager.GetCSS();
  23.       this.inputboxLwSearchResults.wordWrap = true;
  24.       this.inputboxLwSearchResults.multiline = true;
  25.       this.mc_LWSRGrab.useHandCursor = false;
  26.       this.mc_LWSRGrab.onPress = function()
  27.       {
  28.       };
  29.       this.lboxLwSearchResult.__set__rowHeight(22);
  30.       this.lboxLwSearchResult.embedFonts = true;
  31.       this.lboxLwSearchResult.addEventListener("change",mx.utils.Delegate.create(this,this.onItemSelected));
  32.       this.lboxLwSearchResult.setStyle("borderStyle","none");
  33.       this.lboxLwSearchResult.setStyle("borderColor",12566711);
  34.       this.lboxLwSearchResult.setStyle("selectionColor",16099163);
  35.       this.lboxLwSearchResult.setStyle("rollOverColor",16703406);
  36.       this.lboxLwSearchResult.setStyle("textRollOverColor",0);
  37.       this.lboxLwSearchResult.setStyle("textSelectedColor",16777215);
  38.       this.lboxLwSearchResult.setCellRenderer("HtmlListboxCellRenderer");
  39.    }
  40.    function onSearch(evtObj)
  41.    {
  42.    }
  43.    function onItemSelected(evtObj)
  44.    {
  45.       if(!this.mLemmaViewer)
  46.       {
  47.          return undefined;
  48.       }
  49.       var _loc3_ = evtObj.target;
  50.       var _loc2_ = _loc3_.dataProvider.getItemAt(_loc3_.selectedIndex);
  51.       var _loc4_ = _loc2_.start;
  52.       var _loc5_ = _loc2_.end;
  53.       var _loc7_ = _loc2_.context;
  54.       var _loc6_ = _loc2_.contextParm;
  55.       this.mLemmaViewer.Hilite(_loc7_,_loc6_,_loc4_,_loc5_);
  56.    }
  57.    function onItemRollOver(evtObj)
  58.    {
  59.    }
  60.    function onItemRollOut(evtObj)
  61.    {
  62.    }
  63.    function SetSearchResults(inLemmaViewer, inSearchData)
  64.    {
  65.       this.mLemmaViewer = inLemmaViewer;
  66.       this.mLemma = inLemmaViewer.mLemma;
  67.       this.mSearchData = inSearchData;
  68.       this.Search();
  69.    }
  70.    function Search()
  71.    {
  72.       if(!this.mLemma || !this.mSearchData)
  73.       {
  74.          return undefined;
  75.       }
  76.       var _loc3_ = this.mSearchData.searchedText;
  77.       this.clearUI();
  78.       this.inputboxLwSearchResults.htmlText = "<span class=\"s_content\"><span class=\"s_Bold\">Testo ricercato:</span> " + _loc3_ + "</span>";
  79.       this.doSearch(_loc3_,this.mLemma.mTitolo,"title",0);
  80.       if(this.mSearchData.fullTextSearch)
  81.       {
  82.          if(this.mLemma.HaveAbstract())
  83.          {
  84.             this.doSearch(_loc3_,this.mLemma.GetAbstractText(),"abstract",0);
  85.          }
  86.          var _loc4_ = this.mLemma.GetChapterLenght();
  87.          var _loc2_ = 0;
  88.          while(_loc2_ < _loc4_)
  89.          {
  90.             this.doSearch(_loc3_,this.mLemma.GetChapterTitle(_loc2_),"chapterTitle",_loc2_);
  91.             this.doSearch(_loc3_,this.mLemma.GetChapterText(_loc2_),"chapterText",_loc2_);
  92.             _loc2_ = _loc2_ + 1;
  93.          }
  94.       }
  95.       this.lboxLwSearchResult.sortItemsBy("start","ASC");
  96.    }
  97.    function doSearch(inSearchWords, inHtmlText, inWhere, inWhereParam)
  98.    {
  99.       _global.gHtmlRenderer.htmlText = inHtmlText;
  100.       var _loc11_ = _global.gHtmlRenderer.text;
  101.       var _loc28_ = _root.gNormalize.Normalize(inSearchWords);
  102.       var _loc29_ = _root.gNormalize.Normalize(_loc11_);
  103.       var _loc26_ = 36;
  104.       var _loc6_ = undefined;
  105.       var _loc23_ = " " + _loc29_.text + " ";
  106.       var _loc27_ = _loc28_.text;
  107.       if(this.mSearchData.caseSensitive == false)
  108.       {
  109.          _loc23_ = _loc23_.toLowerCase();
  110.          _loc27_ = _loc27_.toLowerCase();
  111.       }
  112.       var _loc24_ = _loc27_.split(" ");
  113.       var _loc15_ = 0;
  114.       while(_loc15_ < _loc24_.length)
  115.       {
  116.          var _loc8_ = StringUtils.trim(_loc24_[_loc15_]);
  117.          if(_loc8_.length > 0)
  118.          {
  119.             if(this.mSearchData.wholeWord)
  120.             {
  121.                _loc8_ = " " + _loc8_ + " ";
  122.             }
  123.             var _loc7_ = length(_loc8_);
  124.             var _loc12_ = Math.round((_loc26_ - _loc7_) / 2);
  125.             var _loc5_ = undefined;
  126.             var _loc4_ = 0;
  127.             var _loc14_ = undefined;
  128.             var _loc13_ = undefined;
  129.             do
  130.             {
  131.                _loc5_ = _loc23_.indexOf(_loc8_,_loc5_);
  132.                if(_loc5_ >= 0)
  133.                {
  134.                   _loc4_ = _loc5_ - 1;
  135.                   _loc14_ = _loc11_.substring(_loc4_ - _loc12_,_loc4_);
  136.                   _loc13_ = _loc11_.substring(_loc4_ + _loc7_,_loc5_ + _loc7_ + _loc12_);
  137.                   _loc6_ = "..." + _loc14_ + "<span class=\"s_Bold\">" + _loc11_.substring(_loc4_,_loc4_ + _loc7_) + "</span>" + _loc13_ + "...";
  138.                   _loc6_ = _loc6_.split("\n").join(" ");
  139.                   _loc6_ = _loc6_.split("\r").join(" ");
  140.                   var _loc20_ = {};
  141.                   var _loc9_ = _loc4_;
  142.                   var _loc10_ = _loc4_ + _loc7_;
  143.                   if(this.mSearchData.wholeWord)
  144.                   {
  145.                      _loc9_ += 1;
  146.                      _loc10_ -= 1;
  147.                   }
  148.                   this.lboxLwSearchResult.addItem({label:_loc6_,start:_loc9_,end:_loc10_,context:inWhere,contextParm:inWhereParam});
  149.                }
  150.                _loc5_ = _loc5_ + 1;
  151.             }
  152.             while(_loc5_ > 0);
  153.             
  154.          }
  155.          _loc15_ = _loc15_ + 1;
  156.       }
  157.    }
  158.    function clearUI()
  159.    {
  160.       this.lboxLwSearchResult.removeAll();
  161.       this.inputboxLwSearchResults.text = "";
  162.    }
  163. }
  164.